\encoding{utf8}
\name{cphsoc_convert_from_spss}
\alias{cphsoc_convert_from_spss}
\title{Convert a SPSS sav-file to various other formats}
\description{
  Convert a SPSS sav-file to RData, Stata, and csv formats.
}
\usage{cphsoc_convert_from_spss(spss_file_path,out_dirname='',out_filename='',
        na='',source_enc='',target_enc='',save_robj=TRUE,save_csv=TRUE,
        save_varlist=TRUE,save_stata=TRUE,dta_replace=FALSE)}
\arguments{
  \item{spss_file_path}{character, SPSS sav file, to convert}
  \item{out_dirname}{character, alternative output directory (default is to use directory of input file)}
  \item{out_filename}{character, alternative output filename (default is to use filename of input file as base for ouput files)}
  \item{na}{character, how to represent NA (missing values)}
  \item{source_enc}{character, encoding of input file if conversion is needed (default is no conversion)}
  \item{target_en}{character, encoding of target files, if conversion is needed (default is no conversion)}
  \item{save_robj}{logical, save an output file in RData format}
  \item{save_csv}{logical, save an output file in RData format}
  \item{save_varlist}{logical, save a table of variables in html format}
  \item{save_stata}{logical, save an output file in Stata format (save a csv-file specifically formatted to comply with Stata format and a do-file to import data)}
  \item{dta_replace}{logical, add 'replace' to Stata do-file (an existing dta file will be automatically overwritten at import)}
}
\value{
  A character vector reporting the files saved.
  
  One or more datasets will be saved. Depending on requested formats the function will save in R-format (RData), raw csv format, and Stata format.
}
\details{
  The Stata format has a number of limitations compared to SPSS and R formats: 
  
  Variable names: Variable names can be up to 32 characters, they must not contain various special characters that are perfectly legal in SPSS and R.
  Stata variable names can contain non-ascii characters like Danish letters but they cannot be the first character. Therefore all names are adjusted to these limitations.
  
  Number of variables: The basic license which is the most common only 2027 variables are allowed, therefore if this is an issue datasets that exceed this limit must be divided into two datasets.
  This function does not do that (we could consider this for a future version).
  
  String variables special issues: String variables that contain data with double quotes has proven to not convert correctly, therefore all double quotes within string values are replaced with single quotes.
}
\seealso{
  \code{\link{read.spss}}
}
\author{Finn Sandø}
\keyword{cphsoc}
\keyword{read.spss}
\keyword{foreign}
